#pragma once
#include "Poco/Util/ServerApplication.h"
#include "Poco/Util/Option.h"
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h"
#include "Poco/Util/AbstractConfiguration.h"
#include "Poco/RecursiveDirectoryIterator.h"
#include "Poco/HashMap.h"
#include "Poco/AutoPtr.h"

#include "Poco/Path.h"
#include <map>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "OutdateStrategy.h"
using Poco::Util::ServerApplication;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::HelpFormatter;
using Poco::Util::AbstractConfiguration;
using Poco::Util::OptionCallback;
using Poco::SiblingsFirstRecursiveDirectoryIterator;
using Poco::AutoPtr;

namespace Poco {
	class File;
}



class Cryptoer;
class MainApp :
	public ServerApplication
{
public:
	MainApp();
	~MainApp();
protected:
	void initialize(Application& self);

	void uninitialize();

	void reinitialize(Application& self);

	void defineOptions(OptionSet& options);

	void handleHelp(const std::string& name, const std::string& value);

	void handleDecode(const std::string& name, const std::string& value);
	void handleEncode(const std::string& name, const std::string& value);
	void handleCleanSrc(const std::string& name, const std::string& value);
	void handleCleanSrcs(const std::string& name, const std::string& value);
	void handleOutdateStrategy(const std::string& name, const std::string& value);
	void handleInit(const std::string& name, const std::string& value);
	void handleViewDec(const std::string&name, const std::string& value);
	void handleWatch(const std::string&name, const std::string& value);
	void handleBackup(const std::string&name, const std::string& value);
	void handleRestore(const std::string&name, const std::string& value);
	void handleListBackup(const std::string&name, const std::string& value);
	void displayHelp();
	std::string readContents(const Poco::File& file);
	void writeContents(const std::string& outpathname, const std::string& contents);
	int main(const ArgVec& args);


private:
	bool _helpRequested;
	bool _initRequested;
	bool _encode;
	bool _decode;
	bool _cleansrc;
	bool _cleansrcs;
	bool _viewmode;
	bool _watchmode;
	bool _backup;
	bool _restore;
	bool _checkconfig;
	time_t _restore_ver;
	std::string _viewContents;
	std::string _srcPathName;
	std::string _srcsPathName;
	Poco::Path _srcPath;
	Poco::Path _srcsPath;
	
	

	E_OUTDATE_STRATEGY _outdateStrategy=E_OUTDATE_STRATEGY::TIMESTAMP;


};

